package com.madev.isellcrazyitems;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.madev.isellcrazyitems.entity.Product;
import com.madev.isellcrazyitems.entity.Reservation;
import com.madev.isellcrazyitems.entity.User;
import com.madev.isellcrazyitems.handler.DatabaseHandler;
import com.madev.sales.R;

public class ReservationActivity extends ListActivity 
{
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        
        /**
         * Dashboard Screen for the application 
         * */        
        // Check login status in database
        
		// Get listview
		ListView lv = getListView();
		
		ArrayList<HashMap<String, String>> reservationsList = new ArrayList<HashMap<String, String>>();
        
        DatabaseHandler db = new DatabaseHandler(getApplicationContext());
        User u = db.getLogin();
        
        
        ArrayList<Reservation> rList = new ArrayList<Reservation>();
        rList = db.getReservationListByUserEmail(u.getUserEmail());
        
        
        for (int i=0; i<rList.size(); i++)
        {
        	HashMap<String, String> map = new HashMap<String, String>();
    		map.put("reservationId", Integer.toString(rList.get(i).getReservationId()));
    		
    		Product p = db.getProductByProductIdNo(rList.get(i).getProductIdNo());

    		map.put("productName", p.getProductName());
    		map.put("quantity", Integer.toString(rList.get(i).getQuantity()));
    		map.put("reserveCreateDate", rList.get(i).getReserveCreateDate());
    		reservationsList.add(map);
        }
        
		ListAdapter adapter = new SimpleAdapter(
				ReservationActivity.this, reservationsList,
				R.layout.list_item, new String[] { "reservationId", "productName",
						"quantity", "reserveCreateDate"},
				new int[] { R.id.reservationId ,R.id.productName, R.id.quantity, R.id.reserveCreateDate });
		// updating listview
		setListAdapter(adapter);
        
        
        
    }
}